I have a function to modify an enumerated attribute type and I am 100% sure that this function works. It is similar to what I posted here, http://www.ibm.com/developerworks/forums/thread.jspa?threadID=379624&tstart=0. I have an attribute that is a multi valued enum - one that people who hate/are afraid of doors will have to edit and possibly add a new value to. I added the value "Add New" to this OE and have written a trigger to execute when "Add New" is selected for this attribute. The trigger opens a simple DB where they can enter the text and select another option or two, then add the new value to the enum. The modify command - shown in the referenced thread - is causing an exception access violation and I can not figure out why for the life me. The only difference between the error version and a version that works fine is that this one is written in a string so I escaped all quotes and such. My first thought was that since the trigger is caused by the attribute, it may not be possible to edit the type - but I don't think that is so because I changed the code to change the attribute's value and there were no issues with that. I am 99% sure that I am not getting the wrong type from the Skip or leaving anything undeleted or anything like that. Any ideas? Here is a snippet of the code which is embedded in a string. |
Re: Modify Enum from Trigger void addtoEnum(string enumName, string newVal, bool isOptional){ current = mod AttrType at = find(mod, enumName) if (null at){ errorBox(enumName \" not found\") return } Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant int i // first, put the existing enum values into the skip for (i = 0; i < at.size; i++){ if (at.strings[i] != \"Add New\"){ put(enumVals, at.strings[i], i\"\") } } // put the new value into the skip put(enumVals, newVal, i\"\") // modify the enumeration Array aModify = create(at.size + 1, 4) // (*,0) contains strings // (*,1) contains associated index // (*,2) contains color value, -1 = don't care // (*,3) contains mapping string temp, insVal, errMsg = null int j = 1 // put sorted skip vals into array put(aModify, \"Add New\", 0 , 0) put(aModify, 0, 0, 1) put(aModify, -1, 0, 2) put(aModify, -1, 0, 3) for temp in enumVals do { insVal = (string key(enumVals)) put(aModify, insVal, j, 0) put(aModify, j, j, 1) put(aModify, -1, j, 2) if (insVal == newVal){ put(aModify, -1, j, 3) } else { put(aModify, j, j, 3) } j++ } // modify the type and delete the array at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation delete(enumVals) delete(aModify) } {code} |
Re: Modify Enum from Trigger SystemAdmin - Tue Aug 09 18:21:46 EDT 2011
it has been a horribly long day, sorry
void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}
Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i
// first, put the existing enum values into the skip
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}
// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation
delete(enumVals)
delete(aModify)
}
|
Re: Modify Enum from Trigger SystemAdmin - Tue Aug 09 18:22:52 EDT 2011
it has been a horribly long day, sorry
void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}
Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i
// first, put the existing enum values into the skip
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}
// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation
delete(enumVals)
delete(aModify)
}
Not sure what to suggest so I'll babble: [] Try post -save-attr trigger that sees if "Add New" is one of the current values. Nit-Picks: I really don't see how your code could work but perhaps I'm missing something. [] I see that you insist on sorting the Enums alphabetically because the string value is the KEY to your skip. If you made "i" the KEY you would preserve the original order. But what you have seems to work if it starts sorted and you want to keep it sorted. [] Your Mapping part needs fixed. If you insert "B" between existing "A"(#0) and "C"(#1), the yes the "B" mapping #1 = -1, but the "C" mapping #2 should be = 1, its original position. My first guess is change... from ... put(aModify, j, j, 3) to ....... put(aModify, k++, j, 3) setting k=0 before the loop.
|
Re: Modify Enum from Trigger SystemAdmin - Tue Aug 09 18:22:52 EDT 2011
it has been a horribly long day, sorry
void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}
Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i
// first, put the existing enum values into the skip
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}
// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation
delete(enumVals)
delete(aModify)
}
if you say for yourself, that the only difference between the working and non-working versions is only that one of them is written "in a string", it sounds reasonable, that you do something very naughty outside the code you posted, that will make the code crash once you call it. Are you maybe using eval_ to execute that code? There are a lot of pitfalls with eval_ so maybe can you tell us, how you call the code from the string? Regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Modify Enum from Trigger Mathias Mamsch - Wed Aug 10 10:57:23 EDT 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Modify Enum from Trigger llandale - Wed Aug 10 09:55:47 EDT 2011
|
Re: Modify Enum from Trigger SystemAdmin - Wed Aug 10 11:38:05 EDT 2011 So you have 5 previous enums numbered #0-#4 and you add a new one in the middle for now 6 numbered #0-#5. The last enum in your Array #5 will have a mapping to previous enum also #5; but there is no such previous Enum. I suppose that could cause an exception. Try my "k++" solution which will result in #5 (the new last one) mapping to #4 (the previous last one). Position: 0 1 2 3 4 Old Enums: A B D E New Enums: A B C D E // inserting "C" Map Needed: 0 1 - 2 3 Map Actual: 0 1 - 3 4 // your algorithm
|
Re: Modify Enum from Trigger llandale - Wed Aug 10 15:17:38 EDT 2011 So you have 5 previous enums numbered #0-#4 and you add a new one in the middle for now 6 numbered #0-#5. The last enum in your Array #5 will have a mapping to previous enum also #5; but there is no such previous Enum. I suppose that could cause an exception. Try my "k++" solution which will result in #5 (the new last one) mapping to #4 (the previous last one). Position: 0 1 2 3 4 Old Enums: A B D E New Enums: A B C D E // inserting "C" Map Needed: 0 1 - 2 3 Map Actual: 0 1 - 3 4 // your algorithm
I tried the k++ solution and I'm getting the same issue. And I do deselect the "Add New" after the modify command, I also am trying to assign the new value at that point to but I cant assign it yet because the modify isn't working.
int j = 1, k = 0
// put sorted skip vals into array, keep "Add New" at the top
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, 0, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, k++, j, 3) // as per louie's suggestion
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg)
delete(enumVals)
delete(aModify)
|
Re: Modify Enum from Trigger SystemAdmin - Wed Aug 10 15:40:31 EDT 2011
I tried the k++ solution and I'm getting the same issue. And I do deselect the "Add New" after the modify command, I also am trying to assign the new value at that point to but I cant assign it yet because the modify isn't working.
int j = 1, k = 0
// put sorted skip vals into array, keep "Add New" at the top
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, 0, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, k++, j, 3) // as per louie's suggestion
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg)
delete(enumVals)
delete(aModify)
|
Re: Modify Enum from Trigger llandale - Wed Aug 10 17:55:25 EDT 2011
-Adam |
Re: Modify Enum from Trigger SystemAdmin - Wed Aug 10 18:29:56 EDT 2011
It does prevent duplicates in the Skip, but you are still commanding a change to the Type with enumerations that are the same and mapping that is not, and for some reason it cannot handle it. Your mapping algorithm, especially when I changed it to k++, presumes the New Value was NOT already defined and is INSERTING, moving the other's down.
Module mod = current()
void addtoEnum(string enumName, string newVal, bool isOptional)
{
current = mod
AttrType at = find(mod, enumName)
if (null at)
{ errorBox(enumName " not found")
return
}
Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i
// first, put the existing enum values into the skip
for (i = 0; i < at.size; i++)
{ if (at.strings[i] != "Add New")
{ put(enumVals, at.strings[i], i "")
}
}
// put the new value into the skip
put(enumVals, newVal, i "")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1, k = 1 // K=1
// put sorted skip vals into array, keep "Add New" at the top
put(aModify, "Add New", 0, 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, 0, 0, 3) // put(aModify, -1, 0, 3)
for temp in enumVals do
{ insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal) //
then put(aModify, -1, j, 3)
else put(aModify, k++, j, 3) // as per louie's suggestion
j++
}
// modify the type and delete the array
print "i\tSkipEnum\t----------\n"
for temp in enumVals do
{ insVal = (string key enumVals)
print temp "\t" insVal "\n"
}
print "i\tName.. \tNum\tColor\tMap\t----------\n"
for (i=0; i<j; i++)
{ print i "\t" (string get(aModify, i, 0)) //
"\t" (int get(aModify, i, 1)) //
"\t" (int get(aModify, i, 2)) //
"\t" (int get(aModify, i, 3)) //
"\n"
}
at = modify(at, enumName, aModify, errMsg)
delete(enumVals)
delete(aModify)
} // end addtoEnum()
addtoEnum("aPrulhiere_Fiasco", "CCCCCC", true)
// #include <InProgress\Temp2.dxl>
Module mod = current
string DXLCode = readFile("c:/Doors-Stuff/DXL-Local/InProgress/Temp2.dxl")
string NameTrig = "Prulhiere_Fiasco"
string NameAttr = "aPrulhiere_Fiasco"
Trigger trg
for trg in mod do
{ if (name(trg) == NameTrig)
{ delete(trg)
break
}
}
if (!confirm("Deploy Trig??")) halt
trg = trigger(NameTrig, module->attribute, post, save, 5, DXLCode)
|
Re: Modify Enum from Trigger llandale - Thu Aug 11 10:34:23 EDT 2011
It does prevent duplicates in the Skip, but you are still commanding a change to the Type with enumerations that are the same and mapping that is not, and for some reason it cannot handle it. Your mapping algorithm, especially when I changed it to k++, presumes the New Value was NOT already defined and is INSERTING, moving the other's down.
Module mod = current()
void addtoEnum(string enumName, string newVal, bool isOptional)
{
current = mod
AttrType at = find(mod, enumName)
if (null at)
{ errorBox(enumName " not found")
return
}
Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i
// first, put the existing enum values into the skip
for (i = 0; i < at.size; i++)
{ if (at.strings[i] != "Add New")
{ put(enumVals, at.strings[i], i "")
}
}
// put the new value into the skip
put(enumVals, newVal, i "")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1, k = 1 // K=1
// put sorted skip vals into array, keep "Add New" at the top
put(aModify, "Add New", 0, 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, 0, 0, 3) // put(aModify, -1, 0, 3)
for temp in enumVals do
{ insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal) //
then put(aModify, -1, j, 3)
else put(aModify, k++, j, 3) // as per louie's suggestion
j++
}
// modify the type and delete the array
print "i\tSkipEnum\t----------\n"
for temp in enumVals do
{ insVal = (string key enumVals)
print temp "\t" insVal "\n"
}
print "i\tName.. \tNum\tColor\tMap\t----------\n"
for (i=0; i<j; i++)
{ print i "\t" (string get(aModify, i, 0)) //
"\t" (int get(aModify, i, 1)) //
"\t" (int get(aModify, i, 2)) //
"\t" (int get(aModify, i, 3)) //
"\n"
}
at = modify(at, enumName, aModify, errMsg)
delete(enumVals)
delete(aModify)
} // end addtoEnum()
addtoEnum("aPrulhiere_Fiasco", "CCCCCC", true)
// #include <InProgress\Temp2.dxl>
Module mod = current
string DXLCode = readFile("c:/Doors-Stuff/DXL-Local/InProgress/Temp2.dxl")
string NameTrig = "Prulhiere_Fiasco"
string NameAttr = "aPrulhiere_Fiasco"
Trigger trg
for trg in mod do
{ if (name(trg) == NameTrig)
{ delete(trg)
break
}
}
if (!confirm("Deploy Trig??")) halt
trg = trigger(NameTrig, module->attribute, post, save, 5, DXLCode)
I am still getting the exception access violation though. Now it says that the error is caused by "delete(aModify)" but I don't think it's right. I commented some lines out and it looks like it's still the "at = modify..." that is causing there error. But now when it happens it only says 38% of memory is in use where as before it was anywhere from 54-62%. -Adam |
Re: Modify Enum from Trigger SystemAdmin - Fri Aug 12 15:14:43 EDT 2011 You could start with my code and slowly make it look like your code, running it frequently, until you get your exception.
|
Re: Modify Enum from Trigger llandale - Sun Aug 14 23:45:44 EDT 2011
-Adam |
Re: Modify Enum from Trigger SystemAdmin - Mon Aug 15 10:31:41 EDT 2011 |
Re: Modify Enum from Trigger SystemAdmin - Mon Aug 15 11:05:23 EDT 2011
You see nothing wrong looking at the print statements from my code?
int i
// Check for existing value
for (i = 0; i < at.size; i++)
{ if (at.strings[i] != newVal
{ errorBox("New value already exists: '" newVal "'")
return
}
} // end check for existing value
|
Re: Modify Enum from Trigger llandale - Mon Aug 15 11:52:11 EDT 2011
You see nothing wrong looking at the print statements from my code?
int i
// Check for existing value
for (i = 0; i < at.size; i++)
{ if (at.strings[i] != newVal
{ errorBox("New value already exists: '" newVal "'")
return
}
} // end check for existing value
|
Re: Modify Enum from Trigger SystemAdmin - Mon Aug 15 11:58:11 EDT 2011 |
Re: Modify Enum from Trigger SystemAdmin - Mon Aug 15 12:33:29 EDT 2011
I finally figured it out! It was an issue with the mapping and new value addition like you suggested earlier. Here is the final version that is working correctly.
AttrType at = find(mod, adType)
if (null at){
errorBox(\"Type Not Found\")
halt()
}
Array aModify = create(at.size + 1, 4)
Skip enumVals = createString() // KEY: string - new OE; DATA: int - mapping value
int i
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"New OE\"){
put(enumVals, at.strings[i], i)
}
}
string newVal = (string get(newOEtext))
put(enumVals, newVal, -1)
put(aModify, \"New OE\", 0, 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, 0, 0, 3)
int temp, j = 1
string eVal, errorMsg = \"\"
for temp in enumVals do {
eVal = (string key(enumVals))
put(aModify, eVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
put(aModify, temp, j, 3)
j++
}
at = modify(at, adType, aModify, errorMsg)
delete(enumVals)
delete(aModify)
|
Re: Modify Enum from Trigger SystemAdmin - Mon Aug 15 11:58:11 EDT 2011 { if (at.strings[i] == newVal) |
Re: Modify Enum from Trigger llandale - Mon Aug 15 17:58:56 EDT 2011 -Adam |
Re: Modify Enum from Trigger SystemAdmin - Wed Aug 17 15:22:49 EDT 2011
This is no-doubt a "current module" problem. Some commands including the "modify" presume the current module. In your case it seems that the current module is changing to the other module after you open it. Thus, your "modify" command is being applied to the other module which is not open for Edit. Module mod = module(trg) ... Module mCurr = current // Remember which one is currently Current current = mod // set this one current deal with modify et tal if (!null mCurr) current = mCurr // Re-instate the previous Current
|
Re: Modify Enum from Trigger llandale - Thu Aug 18 15:55:48 EDT 2011
This is no-doubt a "current module" problem. Some commands including the "modify" presume the current module. In your case it seems that the current module is changing to the other module after you open it. Thus, your "modify" command is being applied to the other module which is not open for Edit. Module mod = module(trg) ... Module mCurr = current // Remember which one is currently Current current = mod // set this one current deal with modify et tal if (!null mCurr) current = mCurr // Re-instate the previous Current
-Adam |